package com.maimao.user.service;

import cn.hutool.core.util.ObjectUtil;
import com.maimao.core.constant.RedisKeys;
import com.maimao.model.user.vo.BankVo;
import com.maimao.user.mapper.ProvinceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2021/5/13 下午7:38
 */
@Service
public class BankService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ProvinceMapper provinceMapper;

    public List<BankVo> bankData() {
        String key = RedisKeys.BANK_TREE;
        //银行这边的缓存可以优化的 key太大了 赶答辩先这样
        List<BankVo> bankList = redisTemplate.opsForList().range(key, 0, -1);
        if (ObjectUtil.isEmpty(bankList)) {
            bankList = provinceMapper.selectAll();
            redisTemplate.opsForList().rightPushAll(key, bankList);
        }
        return bankList;
    }

}
